/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */

define(['adminapp','bootstrap-datepicker', 'bootstrap-datepicker-zh'], function ($app) {
    $app.navactive('brand_stat');

    $('.date-picker').datepicker({
        language      : 'zh-CN',
        rtl: App.isRTL(),
        autoclose: true
    });

    $("#export_btn").on("click",function(){
        var start = $("input#start_date").val();
        var end = $("input#end_date").val();
        if(start==""){
            start = end;
        }
        if(end==""){
            end = start;
        }
        window.location.href = g.ctx + 'admin/stat/brand/export?start_date='+ start + '&end_date='+end;
    });

    var $listtable = $app.listtable({
        'sAjaxSource': g.ctx + "admin/stat/brand/list",
        'bSort' : true,
        'bAutoWidth':true,
        'fnServerParams': function (aoData) {
            var sd = $('#search_form').serializeJSON();
            $.each(sd, function (name, val) {
                aoData.push({"name": name, "value": val});
            });
        },
        'aoColumns': [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'name'},
            {'mDataProp': 'count_date'},
            {'mDataProp': 'times' }
        ]
    }, 'data-list');

    $('#search_btn').on('click', function (e) {
        e.preventDefault();
        $listtable.fnReloadAjax();
    });
});

